home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / plug-ins / imagemap / imap_tools.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-11-05  |  5.1 KB  |  206 lines

  1. /*
  2.  * This is a plug-in for the GIMP.
  3.  *
  4.  * Generates clickable image maps.
  5.  *
  6.  * Copyright (C) 1998-1999 Maurits Rijk  lpeek.mrijk@consunet.nl
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to the Free Software
  20.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21.  *
  22.  */
  23.  
  24. #include "config.h"
  25.  
  26. #include "imap_circle.h"
  27. #include "imap_edit_area_info.h"
  28. #include "imap_main.h"
  29. #include "imap_menu.h"
  30. #include "imap_misc.h"
  31. #include "imap_polygon.h"
  32. #include "imap_popup.h"
  33. #include "imap_rectangle.h"
  34. #include "imap_tools.h"
  35.  
  36. #include "libgimp/stdplugins-intl.h"
  37.  
  38. #include "arrow.xpm"
  39. #include "rectangle.xpm"
  40. #include "circle.xpm"
  41. #include "polygon.xpm"
  42. #include "delete.xpm"
  43. #include "edit.xpm"
  44.  
  45. static gboolean _callback_lock;
  46. static Tools_t _tools;
  47.  
  48. static void
  49. tools_command(GtkWidget *widget, gpointer data)
  50. {
  51.    CommandFactory_t *factory = (CommandFactory_t*) data;
  52.    Command_t *command = (*factory)();
  53.    command_execute(command);
  54. }
  55.  
  56. void 
  57. arrow_on_button_press(GtkWidget *widget, GdkEventButton *event, gpointer data)
  58. {
  59.    if (event->button == 1) {
  60.       if (event->type == GDK_2BUTTON_PRESS)
  61.      edit_shape((gint) event->x, (gint) event->y);
  62.       else
  63.      select_shape(widget, event);
  64.    } else {
  65.       do_popup_menu(event);
  66.    }
  67. }
  68.  
  69. static void
  70. arrow_clicked(GtkWidget *widget, gpointer data)
  71. {
  72.    if (_callback_lock) {
  73.       _callback_lock = FALSE;
  74.    } else {
  75.       set_arrow_func();
  76.       menu_select_arrow();
  77.       popup_select_arrow();
  78.    }
  79. }
  80.  
  81. static void
  82. rectangle_clicked(GtkWidget *widget, gpointer data)
  83. {
  84.    if (_callback_lock) {
  85.       _callback_lock = FALSE;
  86.    } else {
  87.       set_rectangle_func();
  88.       menu_select_rectangle();
  89.       popup_select_rectangle();
  90.    }
  91. }
  92.  
  93. static void
  94. circle_clicked(GtkWidget *widget, gpointer data)
  95. {
  96.    if (_callback_lock) {
  97.       _callback_lock = FALSE;
  98.    } else {
  99.       set_circle_func();
  100.       menu_select_circle();
  101.       popup_select_circle();
  102.    }
  103. }
  104.  
  105. static void
  106. polygon_clicked(GtkWidget *widget, gpointer data)
  107. {
  108.    if (_callback_lock) {
  109.       _callback_lock = FALSE;
  110.    } else {
  111.       set_polygon_func();
  112.       menu_select_polygon();
  113.       popup_select_polygon();
  114.    }
  115. }
  116.  
  117. Tools_t*
  118. make_tools(GtkWidget *window)
  119. {
  120.    GtkWidget *handlebox;
  121.    GtkWidget *toolbar;
  122.  
  123.    _tools.container = handlebox = gtk_handle_box_new();
  124.    toolbar = gtk_toolbar_new(GTK_ORIENTATION_VERTICAL, GTK_TOOLBAR_ICONS);
  125.    gtk_container_set_border_width(GTK_CONTAINER(toolbar), 5);
  126.    gtk_toolbar_set_space_size(GTK_TOOLBAR(toolbar), 5);
  127.    gtk_container_add(GTK_CONTAINER(handlebox), toolbar);
  128.  
  129.    _tools.arrow = make_toolbar_radio_icon(toolbar, window, NULL, arrow_xpm, 
  130.                       _("Select"), 
  131.                                           _("Select existing area"), 
  132.                       arrow_clicked, NULL);
  133.    _tools.rectangle = make_toolbar_radio_icon(toolbar, window, _tools.arrow, 
  134.                           rectangle_xpm, 
  135.                                               _("Rectangle"), 
  136.                           _("Define Rectangle area"), 
  137.                           rectangle_clicked, NULL);
  138.    _tools.circle = make_toolbar_radio_icon(toolbar, window, _tools.rectangle, 
  139.                        circle_xpm, 
  140.                                            _("Circle"),
  141.                        _("Define Circle/Oval area"), 
  142.                        circle_clicked, NULL);
  143.    _tools.polygon = make_toolbar_radio_icon(toolbar, window, _tools.circle, 
  144.                         polygon_xpm, 
  145.                                             _("Polygon"),
  146.                         _("Define Polygon area"), 
  147.                         polygon_clicked, NULL);
  148.    gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
  149.    _tools.edit = make_toolbar_icon(toolbar, window, edit_xpm, 
  150.                                    _("Edit"),
  151.                    _("Edit selected area info"), tools_command,
  152.                    &_tools.cmd_edit);
  153.    gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
  154.    _tools.delete = make_toolbar_icon(toolbar, window, delete_xpm, 
  155.                                      _("Delete"),
  156.                      _("Delete selected area"), tools_command,
  157.                      &_tools.cmd_delete);
  158.  
  159.    gtk_widget_show(toolbar);
  160.    gtk_widget_show(handlebox);
  161.  
  162.    tools_set_sensitive(FALSE);
  163.    set_arrow_func();
  164.  
  165.    return &_tools;
  166. }
  167.  
  168. static void
  169. tools_select(GtkWidget *widget)
  170. {
  171.    _callback_lock = TRUE;
  172.    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE);
  173.    gtk_widget_grab_focus(widget);
  174. }
  175.  
  176. void
  177. tools_select_arrow(void)
  178. {
  179.    tools_select(_tools.arrow);
  180. }
  181.  
  182. void
  183. tools_select_rectangle(void)
  184. {
  185.    tools_select(_tools.rectangle);
  186. }
  187.  
  188. void
  189. tools_select_circle(void)
  190. {
  191.    tools_select(_tools.circle);
  192. }
  193.  
  194. void
  195. tools_select_polygon(void)
  196. {
  197.    tools_select(_tools.polygon);
  198. }
  199.  
  200. void
  201. tools_set_sensitive(gboolean sensitive)
  202. {
  203.    gtk_widget_set_sensitive(_tools.edit, sensitive);
  204.    gtk_widget_set_sensitive(_tools.delete, sensitive);
  205. }
  206.